package com.scsj.supermarket.view.activity.settingmodel;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.jaiky.imagespickers.ImageConfig;
import com.jaiky.imagespickers.ImageSelector;
import com.jaiky.imagespickers.ImageSelectorActivity;
import com.scsj.supermarket.R;

import com.scsj.supermarket.customview.imagespickers.GlideLoader;
import com.scsj.supermarket.view.activity.baseactivitymodel.BaseActivity;
import com.vondear.rxtools.RxPermissionsTool;

import java.util.ArrayList;
import java.util.List;


/**
 * 功能反馈
 */
public class FunctionRecallActivity extends BaseActivity implements View.OnClickListener{

    private ImageView images_pickers;
    private ImageConfig imageConfig;
    private LinearLayout llContainer;
    private ArrayList<String> path = new ArrayList<>();
    public static final int REQUEST_CODE = 123;

    @Override
    protected void createView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_function_recall);

        initToolbar();
        setToolbarTitle("功能反馈");
        hasBack(true);

        RxPermissionsTool.
                with(this).
                addPermission(Manifest.permission.READ_EXTERNAL_STORAGE).
                addPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE).
                initPermission();
    }

    @Override
    protected void initView() {
        images_pickers  = findViewById(R.id.images_pickers);
        llContainer  = findViewById(R.id.llContainer);
    }

    @Override
    protected void initListener() {
        images_pickers.setOnClickListener(this);
    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.images_pickers://图片选择
                imageConfig = new ImageConfig.Builder(
                        new GlideLoader())
                        .steepToolBarColor(getResources().getColor(R.color.titleBlue))
                        .titleBgColor(getResources().getColor(R.color.titleBlue))
                        .titleSubmitTextColor(getResources().getColor(R.color.white))
                        .titleTextColor(getResources().getColor(R.color.white))
                        // 开启多选   （默认为多选）
                        .mutiSelect()
                        // 多选时的最大数量   （默认 9 张）
                        .mutiSelectMaxSize(9)
                        //设置图片显示容器，参数：、（容器，每行显示数量，是否可删除）
                        .setContainer(llContainer, 4, true)
                        // 已选择的图片路径
                        .pathList(path)
                        // 拍照后存放的图片路径（默认 /temp/picture）
                        .filePath("/temp")
                        // 开启拍照功能 （默认关闭）
                        .showCamera()
                        .requestCode(REQUEST_CODE)
                        .build();
                ImageSelector.open(this, imageConfig);
                break;
            default:
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE && resultCode == RESULT_OK && data != null) {
            List<String> pathList = data.getStringArrayListExtra(ImageSelectorActivity.EXTRA_RESULT);

            path.clear();
            path.addAll(pathList);
        }
    }
}
